<?php if(!defined('HDPHP_PATH'))exit;C('SHOW_NOTICE',FALSE);?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<script type="text/javascript" src="http://hd.com/code/shopping/Static/js/jquery-1.8.2.min.js"></script>
		<script src="http://hd.com/code/shopping/Static/hdjs/hdjs.min.js" type="text/javascript" charset="utf-8"></script>
		<link rel="stylesheet" type="text/css" href="http://hd.com/code/shopping/Static/hdjs/hdjs.css"/>
		<link rel="stylesheet" href="http://hd.com/code/shopping/Static/bootstrap/css/bootstrap.min.css"/>
        <link rel="stylesheet" href="http://hd.com/code/shopping/Static/admin/css/common.css" />
		<title>货品列表</title>
	</head>
	<body>
    <div class="container-fluid">
    <div class="row-fluid">
    <div class="span12">    
        <table class='table table-hover table-bordered'>
            <tr class="success">
                <th>货品ID</th>
                <?php foreach ($addData as $key=>$v){?>
                    <th><?php echo $v['title'];?></th>
                <?php }?>
                <th>库存</th>
                <th>货号</th>
                <th>操作</th>
            </tr>
                <tbody>
                <?php foreach ($showData as $k=>$v){?>
                    <tr class="info">
                        <td><?php echo $v['glid'];?></td>
                        <?php foreach ($v['value'] as $k=>$value){?>
                            <td><?php echo $value['ganame'];?></td>
                        <?php }?>
                        <td><?php echo $v['fqty'];?></td>
                        <td><?php echo $v['number'];?></td>
                        <td>
                            <a href="<?php echo U('edit',array('glid'=>$v['glid'],'gid'=>$v['goods_gid']));?>" class="btn btn-primary active">编辑</a>
                            <a href="javascript:del_modal(<?php echo $v['glid'];?>,<?php echo $v['goods_gid'];?>);" class="btn btn-danger active">删除</a>
                        </td>
                    </tr>
                <?php }?>
                </tbody>
    <form action="<?php echo U('addData');?>" method="post">
            <!-- 如果已添加数目小于可能情况数目，才出现添加货品的输入框 -->
            <tr class="info">
                <td>添加货品</td>
                    <?php foreach ($addData as $k=>$v){?>
                        <td>
                            <select name="gaid[]" class="form-control input-sm">
                                <option value="0">请选择</option>
                                    <?php foreach ($v['value'] as $k=>$value){?>
                                        <option value="<?php echo $value['gaid'];?>"><?php echo $value['ganame'];?></option>
                                    <?php }?>
                            </select>
                        </td>
                    <?php }?>
                <td>
                    <input type="text" name='fqty' class="form-control  input-sm" placeholder="输入库存"/>
                </td>
                <td>
                    <input type="text" name='number' value="" class="form-control  input-sm" placeholder="输入货号"/>
                </td>
                <td>
                    <input type="hidden" name="goods_gid" id="" value="<?php echo $addData['0']['goods_gid'];?>" />
                    <input type="submit" value='保存添加' class="btn btn-success active"/>
                </td>
            </tr>
        </table> 
    </form>
    </div>
    </div>
    </div>


	</body>
</html>
<!--删除货品js-->
<script type="text/javascript">
    function del_modal(glid,gid){
        hd_modal({
            width: 400,//宽度
            height: 120,//高度
            title: '确认删除吗？',//标题
            content: '',//提示信息
            button: true,//显示按钮
            button_success: "确定",//确定按钮文字
            button_cancel: "取消",//关闭按钮文字
            timeout: 0,//自动关闭时间 0：不自动关闭
            shade: true,//背景遮罩
            shadeOpacity: 0.3,//背景透明度
            success: function () {//点击确定后的事件
                location.href='<?php echo U("del");?>' + '&glid=' + glid +'&gid=' + gid;
            },
            cancel: function () {//点击关闭后的事件

            }
        });
    }
    $('select[name="gaid[]"]').change(function(){
        var len = $this.length;
        var gaid = $this.children('option').attr('val');
        alert(len);alert(gaid);
    })
    
</script>